package com.yax.mickey.controller;

import com.yax.mickey.common.result.Result;
import com.yax.mickey.entity.Order;
import com.yax.mickey.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ResponseBody
@RestController
@RequestMapping("/order")
@Api(tags = "用户端订单相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/getOrdersByUserId/{userId}")
    @ApiOperation("根据用户ID查询订单信息")
    public Result<List<Order>> getOrdersByUserId(@PathVariable Integer userId) {
        List<Order> orderList = orderService.getOrdersByUserId(userId);
        return Result.success(orderList);
    }

    @GetMapping("/getOrdersByOrderId/{orderId}")
    @ApiOperation("根据订单ID查询订单信息")
    public Result<Order> getOrdersByOrderId(@PathVariable Integer orderId) {
        Order order = orderService.getOrdersByOrderId(orderId);
        return Result.success(order);
    }

    @PostMapping("/addOrders")
    @ApiOperation("新增订单信息")
    public Result<Integer> addOrders(@RequestParam Integer userId) {
        Integer addOrder = orderService.addOrders(userId);
        return Result.success(addOrder);
    }

    @PutMapping("/updateOrders")
    @ApiOperation("更新订单信息")
    public void updateOrders(@RequestBody Order order) {
        orderService.updateOrders(order);
    }

    @DeleteMapping("/deleteOrders")
    @ApiOperation("删除订单信息")
    public void deleteOrders(@RequestBody Order order) {
        orderService.deleteOrders(order);
    }
}
